/**
 * @file lib.lock.h
 * @author maguannan
 * @date 2013/01/28 19:59:34
 * @brief Whatever license applied.
 **/

#include "base.h"
#include <pthread.h>

#ifndef BASE_LIB_LIBLOCK_H
#define BASE_LIB_LIBLOCK_H

#ifdef	__cplusplus
extern "C" {
#endif

struct mlock{
    pthread_mutex_t _lock;
};
int mlock_init(struct mlock *p_lock);
int mlock_lock(struct mlock *p_lock);
int mlock_unlock(struct mlock *p_lock);
/**
 * @brief 
 *
 * @param [in/out] p_lock   : struct mlock*
 * @return  int 
 * @retval   
 * @see 
 * @note 
 * @author maguannan
 * @date 2013/01/30 20:51:34
**/
int mlock_trylock(struct mlock *p_lock);
int mlock_destroy(struct mlock *p_lock);

/*** RW Lock **/
struct rwlock{
    pthread_rwlock_t _lock;
};
int rwlock_init(struct rwlock *p_lock);
int rwlock_wrlock(struct rwlock *p_lock);
int rwlock_trywrlock(struct rwlock *p_lock);
int rwlock_rdlock(struct rwlock *p_lock);
int rwlock_tryrdlock(struct rwlock *p_lock);
int rwlock_unlock(struct rwlock *p_lock);
int rwlock_destroy(struct rwlock *p_lock);

#ifdef	__cplusplus
}
#endif

#endif
/* vim: set tw=0 ts=4 sw=4 et: */


